//
//  YUBottomViw.m
//  QQZone
//
//  Created by 张洪毓 on 15/11/25.
//  Copyright © 2015年 张洪毓. All rights reserved.
//

#import "YUBottomViw.h"
#import "YUBottomButton.h"
@implementation YUBottomViw

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setSubBtnWithImage:@"tabbar_blog"];
        [self setSubBtnWithImage:@"tabbar_mood"];
        [self setSubBtnWithImage:@"tabbar_photo"];
    }
    return self;
}

-(void)setSubBtnWithImage:(NSString *)imageName{
    YUBottomButton *btn = [[YUBottomButton alloc] init];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [self addSubview:btn];
    btn.tag = self.subviews.count;
    [btn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)btnDidClick:(YUBottomButton *)btn{
    NSLog(@"btnDidClick");
}

-(void)setIsLandscape:(BOOL)isLandscape{
    _isLandscape = isLandscape;
    NSUInteger count = self.subviews.count;
    if (isLandscape) {
        for (int i = 0; i < count; i++) {
            YUBottomButton *btn = self.subviews[i];
            CGFloat X = i * kButtonWidth;
            CGFloat Y = 0;
            CGFloat W = kButtonWidth;
            CGFloat H = kButtonWidth;
            btn.frame = CGRectMake(X, Y, W, H);
        }
        
        self.width = count * kButtonWidth;
        self.height = kButtonWidth;
        
    }else {
        
        for (int i = 0; i < count; i++) {
            YUBottomButton *btn = self.subviews[i];
            CGFloat X = 0;
            CGFloat Y = i * kButtonWidth;
            CGFloat W = kButtonWidth;
            CGFloat H = kButtonWidth;
            btn.frame =  CGRectMake(X, Y, W, H);
        }
        
        self.width = kButtonWidth;
        self.height = count * kButtonWidth;
    }
}

@end
